package com.example.demo.buessiness.department.repository;

import com.example.demo.buessiness.user.model.po.User;
import com.example.demo.commons.jpa.JpaRepositoryEnhance;
import com.example.demo.buessiness.department.model.po.Department;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.query.Param;

import java.sql.ResultSet;
import java.util.List;

public interface DepartmentRepository extends JpaRepository<Department,Long> {


    /**
     * 分页方法
     * @param spec
     * @param pageable
     * @return
     */
    Page<Department> findAll(Specification<Department> spec, Pageable pageable);

    /**
     * 获取所有部门 根据时间排序
     * @return
     */
    List<Department> findAllByOrderByIdAsc();

//    @Query(value = "SELECT * FROM department where department=:department",nativeQuery = true)
    public Department findByDepartment(@Param("department") String department);

    /**
     * 查询部门名
     * @param department
     */
    @Modifying
    @Query(value = "SELECT * FROM department WHERE department = ?1 ",nativeQuery=true)
    List<Department> findByDepartmentname(String departmentname);


}
